package com.qf.bigdata.repository;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Bean(name="prestoHikariConfig")
    @ConfigurationProperties(prefix = "spring.datasource.presto")
    public HikariConfig hikariConfig() {
        return new HikariConfig();
    }

    @Bean(name="prestoDataSource")
    public DataSource prestoDataSource(
            @Autowired @Qualifier("prestoHikariConfig") HikariConfig hikariConfig) { //默认按类型匹配
        return new HikariDataSource(hikariConfig);
    }

    @Bean(name="prestoJdbcTemplate")
    public JdbcTemplate prestoJdbcTemplate(
            @Autowired @Qualifier("prestoDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    //clickhouse datasource config

    @Bean(name="clickhouseHikariConfig")
    @ConfigurationProperties(prefix = "spring.datasource.clickhouse")
    public HikariConfig clickhouseHikariConfig() {
        return new HikariConfig();
    }

    @Bean(name="clickhouseDataSource")
    public DataSource clickhouseDataSource(
            @Autowired @Qualifier("clickhouseHikariConfig") HikariConfig hikariConfig) { //默认按类型匹配
        return new HikariDataSource(hikariConfig);
    }

    @Bean(name="clickhouseJdbcTemplate")
    public JdbcTemplate clickhouseJdbcTemplate(
            @Autowired @Qualifier("clickhouseDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }


    //milvus连接信息
    @Value("${spring.data.milvus.host}")
    private String host;
    @Value("${spring.data.milvus.port}")
    private int port;

    @Bean("milvusTemplate")
    public MilvusTemplate milvusTemplate(){
        return new MilvusTemplate(host,port);

    }

    @Value("${spring.data.hbase.quorum}")
    private String quorum;
    @Value("${spring.data.hbase.rootDir}")
    private String rootDir;
    @Value("${spring.data.hbase.zNodeParent}")
    private String zNodeParent;
    @Bean("hbaseTemplate")
    public HBaseTemplate hbaseTemplate(){
        return new  HBaseTemplate(quorum,rootDir,zNodeParent);
    }



}
